-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Android: add native platform support #2396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks a lot for working on this! This looks good to me. I think @gmittert is working on adding support for compiling the manifest file for Windows so that should be helpful for Android as well. |
@swift-ci smoke test |
set.fds_bits = fd_bits | ||
#else | ||
set.__fds_bits = fd_bits | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if I could assign some kind of compile-time symbol reference to each platform's variable name, so that this runtime copying isn't needed.
if localFileSystem.isFile(AbsolutePath("/system/bin/toolbox")) || | ||
localFileSystem.isFile(AbsolutePath("/system/bin/toybox")) { | ||
return .android | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't seem to be called anywhere, can remove if not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah let's remove it if it's dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong, the variable it's used to initialize, currentPlatform
, is used in exactly one place. I suppose this might be useful for TSCUtility and llbuild someday too, for which I've created a Termux package, so I'd like to keep this Android support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you chose these particular files vs /system/build.prop
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No other reason that I'm familiar with toolbox/toybox, as they're sometimes invoked from the Termux command-line, and not build.prop, which is unreadable without root on my device. If there's a better file that signifies Android, glad to use that instead, just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that's fine for now, we can always update the check later if we need to.
Thanks for your contribution!
@@ -60,8 +60,10 @@ public struct DLOpenFlags: RawRepresentable, OptionSet { | |||
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0) | |||
#else | |||
public static let first: DLOpenFlags = DLOpenFlags(rawValue: 0) | |||
#if !os(Android) | |||
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: RTLD_DEEPBIND) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No RTLD_DEEPBIND
on Android, so #ifdef it out here and above.
Hmm, the failed smoke test indicates that the expected type of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! I have concerns about the deployment target, but other than that, looks good.
@@ -1376,6 +1376,7 @@ class PackageBuilderTests: XCTestCase { | |||
"ios": "8.0", | |||
"tvos": "9.0", | |||
"watchos": "2.0", | |||
"android": "7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to set to 0.0 just like linux above for this test to pass.
@@ -1411,6 +1412,7 @@ class PackageBuilderTests: XCTestCase { | |||
"linux": "0.0", | |||
"ios": "8.0", | |||
"watchos": "2.0", | |||
"android": "7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
The macOS smoke test for swiftlang/swift-package-manager#2396 fails without this addition.
350d86d
to
5dd7287
Compare
Alright, figured out the issue with the type of Should be ready to go now, addressed the other issues too. The sourcekit-lsp pull will need to be tested and merged alongside this. |
@swift-ci smoke test |
Please test with the following pull requests: @swift-ci smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just needs the tweak to the target triple.
if localFileSystem.isFile(AbsolutePath("/system/bin/toolbox")) || | ||
localFileSystem.isFile(AbsolutePath("/system/bin/toybox")) { | ||
return .android | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you chose these particular files vs /system/build.prop
?
if localFileSystem.isFile(AbsolutePath("/system/bin/toolbox")) || | ||
localFileSystem.isFile(AbsolutePath("/system/bin/toybox")) { | ||
return .android | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that's fine for now, we can always update the check later if we need to.
Thanks for your contribution!
Please test with the following pull requests: @swift-ci smoke test |
Thanks for the quick review and merge, got many of those tests working in the meantime with an adapted version of #2363, will submit that later. |
This pull was used to build SPM natively on Android in the Termux app, similar to swiftlang/swift#27167. The first commit consists of compile-time changes that were needed to build SPM itself natively on an Android host, whereas the second commit adds some support for using SPM to build for Android. None of the second commit was needed to run the SPM tests on Android, so any of it can be removed if it interferes with any other plans for Android compilation, though there's currently only two mentions of Android in the SPM source.
This pull was tested against the 10/24 source snapshot and out of 623 test cases run, it reports 72 failing. Most are related to looking for PackageDescription4 and other dependencies of SPM itself, which fails here because it can't find them relative to the test case's temporary path. A couple
print
s show that that code path isn't hit on linux, but I'm not familiar enough with the SPM source yet to fix that. In the meantime, I thought I'd get the rest of these changes in.I also had to disable interpreting the SPM manifest to generate the JSON version when bootstrapping, similar to #2363, instead extracting the same command and generating the JSON by compiling the source. Finally, I had to tweak the bootstrap script:
The two preprocessor definitions are needed because Bionic's
strerror_r
used to return a different type before API 23; linking against android-spawn because Termux backported and shippedposix_spawn
in a separate library; and I'm unsure why that lastbuild_target
change was needed, given the prior change for Android (without it, two directories are created with both names and the build errors out). I plan to try cross-compiling SPM itself for Android, so I'll submit a pull for all those build changes later.Two other minor issues while I'm here:
-fmodules-cache-path
on clang from the bootstrap script, on both Android and linux:I'm guessing it's expected that Swift's forked clang is used, but unless it's installed in the system itself, the bootstrap script isn't configured that way. I'm unsure if this was intended or if it matters.